Skip to content

fix: handle notifications/cancelled for valid request ID 0#2502

Open
nankingjing wants to merge 2 commits into
modelcontextprotocol:mainfrom
nankingjing:fix/cancelled-notification-id-zero
Open

fix: handle notifications/cancelled for valid request ID 0#2502
nankingjing wants to merge 2 commits into
modelcontextprotocol:mainfrom
nankingjing:fix/cancelled-notification-id-zero

Conversation

@nankingjing

Copy link
Copy Markdown

Fixes #2283

JSON-RPC allows request ID 0 as a valid identifier, but the SDK's cancelled notification handler treats it as falsy and silently drops the cancellation. This means agent orchestrators cannot cancel tool calls numbered with ID 0.

Fix: Replace truthiness check with explicit undefined check so that 0 is treated as a valid request ID for cancellation.

Changes:

  • packages/core-internal/src/shared/protocol.ts: Change !notification.params.requestId to notification.params.requestId === undefined in _oncancel
  • packages/core-internal/test/shared/protocol.test.ts: Add test verifying cancellation works for request ID 0

JSON-RPC allows 0 as a valid request id, but Protocol._oncancel used a
truthiness check on params.requestId, so a cancellation targeting
request id 0 was silently dropped and the in-flight handler kept
running. Replace the truthiness check with an explicit undefined check.

Fixes modelcontextprotocol#2283
@nankingjing nankingjing requested a review from a team as a code owner July 15, 2026 15:41
@changeset-bot

changeset-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7078a15

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@modelcontextprotocol/client Patch
@modelcontextprotocol/server Patch
@modelcontextprotocol/core Patch
@modelcontextprotocol/server-legacy Patch
@modelcontextprotocol/codemod Patch
@modelcontextprotocol/core-internal Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@2502

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@2502

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@2502

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@2502

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@2502

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@2502

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@2502

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@2502

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@2502

commit: 7078a15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

notifications/cancelled is ignored for request id 0

1 participant